package com.yang.xiao.hui.servlet;

import com.yang.runnable.AsyRunnable;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@WebServlet(name="AsyncServlet", urlPatterns={"/order"},
        asyncSupported = true)
public class OrderServlet extends HttpServlet {
    private ExecutorService executorService =Executors.newFixedThreadPool(10);

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AsyncContext asyncContext = req.startAsync(req, resp);
        ServletResponse response = asyncContext.getResponse();
        response.getWriter().print("之前的。。。。。。");
        asyncContext.setTimeout(2000);
        executorService.submit(new AsyRunnable(asyncContext));
        System.out.println("ddddd");


    }
}
